package com.his.admin.controller;

import com.his.admin.service.MenuService;
import com.his.admin.service.UserService;
import com.his.dao.domain.dto.ListDto;
import com.his.dao.domain.entity.Menu;
import com.his.dao.domain.entity.User;
import com.his.dao.domain.vo.ListVo;
import com.his.util.annotation.RequiresLogin;
import com.his.util.annotation.RequiresPermissions;
import com.his.util.result.RestResult;
import com.his.util.result.RestResultBuilder;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author Fall
 */
@RestController
@RequestMapping("/menu")
@Api(value = "菜单模块")
public class MenuController {
    @Resource
    private MenuService menuService;

    @RequiresLogin
    @RequestMapping("/load")
    @ApiOperation(value = "加载菜单列表",notes = "加载菜单列表")
    public RestResult loadMenu(@RequestHeader("authorization") String authorization) {
        return menuService.load(authorization);
    }

    @RequiresLogin
    @RequiresPermissions
    @RequestMapping("/all")
    @ApiOperation(value = "获取菜单列表",notes = "获取菜单列表")
    public RestResult all(@RequestBody ListDto listDto) {
        return menuService.all(listDto);
    }

    @RequiresLogin
    @RequiresPermissions
    @RequestMapping("/id")
    @ApiOperation(value = "获取菜单id列表",notes = "获取菜单id列表")
    public RestResult selectAllMenuId(@RequestBody ListDto listDto) {
        return menuService.selectAllMenuId(listDto);
    }

    @RequiresLogin
    @RequiresPermissions
    @RequestMapping("/add")
    @ApiOperation(value = "增加菜单列表",notes = "增加菜单列表")
    public RestResult add(@RequestBody Menu menu) {
        if (menuService.save(menu)) {
            return new RestResultBuilder().success();
        }
        return new RestResultBuilder().fail();
    }

    @RequiresLogin
    @RequiresPermissions
    @RequestMapping("/update")
    @ApiOperation(value = "更新菜单列表",notes = "更新菜单列表")
    public RestResult update(@RequestBody Menu menu) {
        if (menuService.updateById(menu)) {
            return new RestResultBuilder().success();
        }
        return new RestResultBuilder().fail();
    }

    @RequiresLogin
    @RequiresPermissions
    @RequestMapping("/delete")
    @ApiOperation(value = "删除菜单列表",notes = "删除菜单列表")
    public RestResult delete(@RequestBody List<Integer> ids) {
        if (menuService.removeByIds(ids)) {
            return new RestResultBuilder().success();
        }
        return new RestResultBuilder().fail();
    }
}
